package engine.gui;

import engine.exceptions.EExceptionCause;
import engine.exceptions.ExceptionHandler;
import engine.exceptions.MADException;
import engine.game.Game;
import engine.game.Manager;
import engine.graphics.TextureManager;

public class PauseMenuScreen extends GameMenuScreen{

	private static final long serialVersionUID = 1L;
	
	protected EScreenState screenState ;
	protected Panel saveScreen, loadScreen, optionsScreen ;  
	
	public PauseMenuScreen(Manager m, Game g) {
		super(m, g);	
		GameMenuScreen.textureGameMenuScreen(this);
		this.addCaptionToScreen("Spiel pausiert");
		this.screenState = EScreenState.MAIN; 
	}
	
	public boolean hasSaveScreen(){ return saveScreen != null; } 
	public boolean hasLoadScreen(){ return loadScreen != null; } 
	public boolean hasOptionsScreen(){ return optionsScreen != null; }
	
	public void gotoMainScreen(){
		this.changeScreenState(EScreenState.MAIN);
	}
	public void gotoSaveScreen(){
		this.changeScreenState(EScreenState.SAVE);
	}
	public void gotoLoadScreen(){
		this.changeScreenState(EScreenState.LOAD);
	}
	public void gotoOptionsScreen(){
		this.changeScreenState(EScreenState.OPTIONS);
	}
	
	private void changeScreenState(EScreenState state){
		this.getMainScreen().hide(); 
		if(this.hasSaveScreen()) this.saveScreen.hide(); 
		if(this.hasLoadScreen()) this.loadScreen.hide(); 
		if(this.hasOptionsScreen()) this.optionsScreen.hide(); 
		try{
			switch(state){
			case MAIN: this.getMainScreen().show(); break; 
			case SAVE: if(this.hasSaveScreen()) saveScreen.show(); break ;
			case LOAD: if(this.hasLoadScreen()) loadScreen.show(); break ; 
			case OPTIONS: if(this.hasOptionsScreen()) optionsScreen.show(); break ; 
			}
			this.screenState = state ; 
		}catch(Exception e){
			ExceptionHandler.displayException(new MADException(EExceptionCause.E_CHANGE_MENU, e));
		}
	}
	
	public void render() {
		if (this.getBackgroundPanel().isTextured())
			TextureManager.bindTexture("gui");
		this.getBackgroundPanel().render();
		switch (this.screenState) {
		case MAIN:
			this.getMainScreen().render();
			break; 
		case SAVE:
			if (this.hasSaveScreen())
				saveScreen.render();
			break;
		case LOAD:
			if (this.hasLoadScreen())
				loadScreen.render();
			break;
		case OPTIONS:
			if (this.hasOptionsScreen())
				optionsScreen.render();
			break;
		}
	}
	
//	public void update() {
//		this.getBackgroundPanel().update(); 
//		switch (this.screenState) {
//		case SAVE:
//			if (this.hasSaveScreen())
//				saveScreen.update();
//			break;
//		case LOAD:
//			if (this.hasLoadScreen())
//				loadScreen.update();
//			break;
//		case OPTIONS:
//			if (this.hasOptionsScreen())
//				optionsScreen.update();
//			break;
//		case MAIN:
//			getMainScreen().update();
//		}
//	}

}
